/**============================================================================
 Confidential Information - Limited distribution to authorized persons only.
 This software is protected as an unpublished work under the U.S. Copyright
 Act of 1976.

 Copyright (c) 2011, BluePhoenix Solutions, Inc. All rights reserved.
 ----------------------------------------------------------------------------
 file......: Base2ButtonsDialog.java
 Author....: Vyacheslav Kovalyov
 Created...: 28.10.11

 Description:

 ============================================================================*/
package ru.monyag.pred.swing.ui.windows;

import ru.monyag.pred.swing.ui.BasePanel;
import ru.monyag.pred.swing.ui.buttons.BaseSwingButton;

import javax.swing.*;
import java.awt.*;

import static java.awt.BorderLayout.CENTER;
import static java.awt.BorderLayout.SOUTH;
import static ru.monyag.pred.swing.util.PredSwingConstants.APPLY_ICON;
import static ru.monyag.pred.swing.util.PredSwingConstants.CANCEL_ICON;

/**
 * @author Vyacheslav Kovalyov
 * @version 1.0
 */
public class Base2ButtonsDialog extends BaseDialog {

    protected Base2ButtonsDialog(String title, int width, int height) {
        super(title, width, height);
        basePanel = new BasePanel();
        add(basePanel, CENTER);

        createButtonsPanel();
    }

    protected void addButton(BaseSwingButton button) {
        buttonsBox.add(button);
    }

    protected void addComponent(Component comp, Object constraints) {
        basePanel.add(comp, constraints);
    }

    private void createButtonsPanel() {
        BasePanel panel = new BasePanel();
        buttonsBox = Box.createHorizontalBox();

        buttonsBox.add(new BaseSwingButton(APPLY_ICON, CENTER_ALIGNMENT) {
            @Override
            public void onClick() {
                onApply();
            }
        });

        buttonsBox.add(new BaseSwingButton(CANCEL_ICON, CENTER_ALIGNMENT) {
            @Override
            public void onClick() {
                onCancel();
            }
        });

        panel.add(buttonsBox, CENTER);
        add(panel, SOUTH);
    }

    protected void onApply() {
        //do nothing by default
    }

    protected void onCancel() {
        //do nothing by default
    }

    private BasePanel basePanel;
    private Box buttonsBox;
}
